package com.zhanghe.study.mapreduce.join;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

import java.io.IOException;

/**
 * @author zh
 * @date 2021/3/30 11:52
 */
public class JoinDriver {
    public static void main(String[] args) throws IOException, ClassNotFoundException, InterruptedException {
        args = new String[]{"/Users/zhanghe/Desktop/user/myself/GitProject/hdfs/src/main/resources/joininput","/Users/zhanghe/Desktop/user/myself/GitProject/hdfs/src/main/resources/joinoutput"};

        Configuration conf = new Configuration();
        // 获取job
        Job job = Job.getInstance(conf);
        // 设置jar的存储位置
        job.setJarByClass(JoinDriver.class);
        // 设置map和reduce
        job.setMapperClass(JoinMapper.class);
        job.setReducerClass(JoinReducer.class);
        // 设置map的输出类型
        job.setMapOutputKeyClass(Text.class);
        job.setMapOutputValueClass(TableBean.class);
        // 设置输出类型
        job.setOutputKeyClass(TableBean.class);
        job.setOutputValueClass(NullWritable.class);
//        job.setInputFormatClass(CombineFileInputFormat.class);
//        CombineFileInputFormat.setMaxInputSplitSize(job,20*1024*1024);
        // 设置输入输出路径
        FileInputFormat.setInputPaths(job,new Path(args[0]));
        FileOutputFormat.setOutputPath(job,new Path(args[1]));

        // 压缩、解压缩
//        DefaultCodec codec = new DefaultCodec();
//        CompressionInputStream compressionInputStream = codec.createInputStream(inputstream);
//        CompressionOutputStream compressionOutputStream = codec.createOutputStream(outputStream);

        // job提交
        job.waitForCompletion(true);
    }
}
